/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Home.java
 *
 * Created on Apr 11, 2009, 11:13:56 AM
 */

package lk.asha.desktop.operator;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.Calendar;
import javax.swing.JPanel;

/**
 *
 * @author Administrator
 */
public class Home extends javax.swing.JFrame implements Runnable{
  Thread runner; //declare global objects
  Font clockFont;
    /** Creates new form Home */
    public Home() {
        initComponents();
        setLocationRelativeTo(null);
        start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        addItem1 = new lk.asha.desktop.operator.AddItem();
        addNewItemToStock1 = new lk.asha.desktop.operator.AddNewItemsToStock();
        addRequiredItem1 = new lk.asha.desktop.operator.AddRequiredItem();
        addDeliveredItem1 = new lk.asha.desktop.operator.AddDeliveredItem();
        addDeliveredItem2 = new lk.asha.desktop.operator.AddDeliveredItem();
        addLoadToVehicle1 = new lk.asha.desktop.operator.AddLoadToVehicle();
        addReturnFromVehicle1 = new lk.asha.desktop.operator.AddReturnFromVehicle();
        addNewCustomer1 = new lk.asha.desktop.operator.AddNewCustomer();
        reportViewer1 = new lk.asha.desktop.operator.ReportViewer();
        reportViewer2 = new lk.asha.desktop.operator.ReportViewer();
        sendSMS1 = new lk.asha.desktop.operator.SendSMS();
        sendSMS2 = new lk.asha.desktop.operator.SendSMS();
        changePassword1 = new lk.asha.desktop.operator.ChangePassword();
        jPanel2 = new lk.asha.desktop.operator.Home.ClockPanel();
        //javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new lk.asha.desktop.style.Style().getMainPannelBlackgroundColor());

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        jTabbedPane1.setMinimumSize(new java.awt.Dimension(600, 400));
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(700, 550));

        addItem1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/addItem.png")), addItem1); // NOI18N

        addNewItemToStock1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        addNewItemToStock1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddNewItemsToStock.png")), addNewItemToStock1); // NOI18N

        addRequiredItem1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddRequiredItem.png")), addRequiredItem1); // NOI18N

        addDeliveredItem1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());

        javax.swing.GroupLayout addDeliveredItem1Layout = new javax.swing.GroupLayout(addDeliveredItem1);
        addDeliveredItem1.setLayout(addDeliveredItem1Layout);
        addDeliveredItem1Layout.setHorizontalGroup(
            addDeliveredItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addDeliveredItem1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addDeliveredItem2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        addDeliveredItem1Layout.setVerticalGroup(
            addDeliveredItem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addDeliveredItem1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addDeliveredItem2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddDeliveredItem.png")), addDeliveredItem1); // NOI18N

        addLoadToVehicle1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddLoadToVehicle.png")), addLoadToVehicle1); // NOI18N

        addReturnFromVehicle1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddReturnFromVehicle.png")), addReturnFromVehicle1); // NOI18N

        addNewCustomer1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/AddNewCustomer.png")), addNewCustomer1); // NOI18N

        reportViewer1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());

        reportViewer2.setBorder(javax.swing.BorderFactory.createLineBorder(new lk.asha.desktop.style.Style().getFullLineColor()));

        javax.swing.GroupLayout reportViewer1Layout = new javax.swing.GroupLayout(reportViewer1);
        reportViewer1.setLayout(reportViewer1Layout);
        reportViewer1Layout.setHorizontalGroup(
            reportViewer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportViewer1Layout.createSequentialGroup()
                .addGap(72, 72, 72)
                .addComponent(reportViewer2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(73, Short.MAX_VALUE))
        );
        reportViewer1Layout.setVerticalGroup(
            reportViewer1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportViewer1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(reportViewer2, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/ReportViewer.png")), reportViewer1); // NOI18N

        sendSMS2.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());

        javax.swing.GroupLayout sendSMS1Layout = new javax.swing.GroupLayout(sendSMS1);
        sendSMS1.setLayout(sendSMS1Layout);
        sendSMS1Layout.setHorizontalGroup(
            sendSMS1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sendSMS1Layout.createSequentialGroup()
                .addComponent(sendSMS2, javax.swing.GroupLayout.PREFERRED_SIZE, 809, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        sendSMS1Layout.setVerticalGroup(
            sendSMS1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(sendSMS2, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/SendSMS.png")), sendSMS1); // NOI18N

        changePassword1.setBackground(new lk.asha.desktop.style.Style().getPannelBlackground());
        changePassword1.setPreferredSize(new java.awt.Dimension(700, 550));
        jTabbedPane1.addTab("", new javax.swing.ImageIcon(getClass().getResource("/image/ChangePassword.png")), changePassword1); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 245, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 119, Short.MAX_VALUE)
        );

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/title1.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1049, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(278, 278, 278)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Home().setVisible(true);
            }
        });
    }
////////////////
   class ClockPanel extends JPanel
     {
      public void paintComponent(Graphics painter )
        {
        Image pic =
          Toolkit.getDefaultToolkit().getImage("background.jpg");

         if(pic != null)

            painter.drawImage(pic, 0, 0, this);     //create image


//if I didn't use a background image I would have used the setColor and fillRect methods to set background
          clockFont = new Font("Serif", Font.BOLD, 40);
          painter.setFont(clockFont);                   //create clock components
          painter.setColor(Color.black);
          painter.drawString( timeNow(), 60, 40);


        }
     }


     //get current time
     public String timeNow()
     {
       Calendar now = Calendar.getInstance();
       int hrs = now.get(Calendar.HOUR_OF_DAY);
       int min = now.get(Calendar.MINUTE);
       int sec = now.get(Calendar.SECOND);

       String time = zero(hrs)+":"+zero(min)+":"+zero(sec);

       return time;
     }



     public String zero(int num)
     {
       String number=( num < 10) ? ("0"+num) : (""+num);
       return number;                                    //Add leading zero if needed

     }


     public void start()
     {
       if(runner == null) runner = new Thread(this);
       runner.start();
                                                             //method to start thread
     }


     public void run()
     {
       while (runner == Thread.currentThread() )
       {
        repaint();
                                                         //define thread task
           try
             {
               Thread.sleep(1000);
             }
              catch(InterruptedException e)
                  {
                    System.out.println("Thread failed");
                  }

       }
     }

    ///////////////////////////
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private lk.asha.desktop.operator.AddDeliveredItem addDeliveredItem1;
    private lk.asha.desktop.operator.AddDeliveredItem addDeliveredItem2;
    private lk.asha.desktop.operator.AddItem addItem1;
    private lk.asha.desktop.operator.AddLoadToVehicle addLoadToVehicle1;
    private lk.asha.desktop.operator.AddNewCustomer addNewCustomer1;
    private lk.asha.desktop.operator.AddNewItemsToStock addNewItemToStock1;
    private lk.asha.desktop.operator.AddRequiredItem addRequiredItem1;
    private lk.asha.desktop.operator.AddReturnFromVehicle addReturnFromVehicle1;
    private lk.asha.desktop.operator.ChangePassword changePassword1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private lk.asha.desktop.operator.ReportViewer reportViewer1;
    private lk.asha.desktop.operator.ReportViewer reportViewer2;
    private lk.asha.desktop.operator.SendSMS sendSMS1;
    private lk.asha.desktop.operator.SendSMS sendSMS2;
    // End of variables declaration//GEN-END:variables

}
